package com.zsk.shop.api.pay.common.util;

import com.zsk.shop.common.base.BizException;
import com.zsk.shop.common.base.BizExceptionEnum;

import java.util.Map;

public class PayUtil {

    public static String wxHandld(Map<String, Object> params) throws BizException {
        String returnCode = (String) params.get("return_code");
        String resultCode = (String) params.get("result_code");
        if (!("SUCCESS".equals(returnCode) && "SUCCESS".equals(resultCode))) {
            throw new BizException(BizExceptionEnum.ERROR.getCode(), "微信请求出错" + params.get("err_code_des"));
        }
        return "";
    }

    public static String wxHandldMsg(Map<String, Object> params) {
        String returnCode = (String) params.get("return_code");
        String resultCode = (String) params.get("result_code");
        if (!("SUCCESS".equals(returnCode) && "SUCCESS".equals(resultCode))) {
            return params.get("err_code_des").toString();
        }
        return "";
    }

    public static String aliHandld(Map<String, Object> result, String key) throws BizException {
        Map<String, Object> map = (Map<String, Object>) result.get(key);
        if (!map.get("msg").equals("Success")) {
            return map.get("sub_msg").toString();
        }
        return "";
    }

}
